package com.hnyfkj.jyindustry.biz.piarea.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hnyfkj.jyindustry.biz.piarea.dao.PiAreaDao;
import com.hnyfkj.jyindustry.biz.piarea.dto.PiAreaInsertDto;
import com.hnyfkj.jyindustry.biz.piarea.dto.PiAreaQueryDto;
import com.hnyfkj.jyindustry.biz.piarea.dto.PiAreaUpdateDto;
import com.hnyfkj.jyindustry.biz.piarea.entity.PiArea;
import com.hnyfkj.jyindustry.biz.piarea.service.PiAreaService;
import com.hnyfkj.jyindustry.biz.piarea.vo.PiAreaVo;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service("piAreaService")
public class PiAreaServiceImpl extends ServiceImpl<PiAreaDao, PiArea> implements PiAreaService {


    @Autowired
    private PiAreaDao piAreaDao;

    @Override
    public PageReturnDto<PiAreaVo> queryPage(PiAreaQueryDto queryDto) {
        PageInfo<PiAreaVo> page =
                PageHelper.startPage(queryDto.getPage(), queryDto.getLimit()).doSelectPageInfo(() -> piAreaDao.selectListByQuery(queryDto));
        return PageReturnDto.pageOf(page);
    }

    @Override
    public int insert(PiAreaInsertDto piAreaInsertDto) {
        final PiArea piScreen = new PiArea();
        BeanUtils.copyProperties(piAreaInsertDto, piScreen);
        return piAreaDao.insert(piScreen);
    }

    @Override
    public int update(PiAreaUpdateDto piAreaUpdateDto) {
        final PiArea piScreen = new PiArea();
        BeanUtils.copyProperties(piAreaUpdateDto, piScreen);
        return piAreaDao.updateById(piScreen);
    }

    @Override
    public int delete(String ids) {
        String[] id = ids.split(",");
        return piAreaDao.deleteBatchIds(Arrays.asList(id));
    }
}